Dart BigInt operator ^
Syntax & Examples


BigInt.operator ^ operator

The `operator ^` in Dart performs a bitwise exclusive-or operation between two BigInt objects.


Syntax of BigInt.operator ^

The syntax of BigInt.operator ^ operator is:

operator ^(BigInt other) → BigInt

This operator ^ operator of BigInt bit-wise exclusive-or operator.

Parameters

ParameterOptional/RequiredDescription
otherrequiredthe BigInt object to perform the bitwise exclusive-or operation with


✐ Examples

1 Perform bit-wise XOR operation

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with different values.
  2. We use the ^ operator to perform a bit-wise exclusive-or operation between num1 and num2.
  3. We print the result of the operation to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(10);
  BigInt num2 = BigInt.from(7);
  BigInt result = num1 ^ num2;
  print('Bit-wise XOR of num1 and num2: $result');
}

Output

Bit-wise XOR of num1 and num2: 13

2 Perform bit-wise XOR operation with hexadecimal numbers

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with hexadecimal values.
  2. We use the ^ operator to perform a bit-wise exclusive-or operation between num1 and num2.
  3. We print the result of the operation to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(0x55);
  BigInt num2 = BigInt.from(0xAA);
  BigInt result = num1 ^ num2;
  print('Bit-wise XOR of num1 and num2: $result');
}

Output

Bit-wise XOR of num1 and num2: 171

3 Perform bit-wise XOR operation with binary numbers

In this example,

  1. We create two BigInt objects, num1 and num2, initialized with binary values.
  2. We use the ^ operator to perform a bit-wise exclusive-or operation between num1 and num2.
  3. We print the result of the operation to standard output.

Dart Program

void main() {
  BigInt num1 = BigInt.from(0b1100);
  BigInt num2 = BigInt.from(0b1010);
  BigInt result = num1 ^ num2;
  print('Bit-wise XOR of num1 and num2: $result');
}

Output

Bit-wise XOR of num1 and num2: 6

Summary

In this Dart tutorial, we learned about operator ^ operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.